<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>


	

	<script>
		
		/**
		* 冒泡排序方法
		*/
	
		var arr = [45,46,3,6,78,9,10,45,6]
	
		function quickSort(arr) {

			var leng = arr.length,
				i = 0;
	
			for(i ; i < leng; i++) {
	
				for(var j = i + 1; j < leng; j++) {
	
					if(arr[i] > arr[j]) {
						wasp(i,j)
					}
	
				}
			}
	
			return arr;
	
		}
	
		function wasp(a,b) {
	
			var tmp = arr[a];
			arr[a] = arr[b];
			arr[b] = tmp;
	
		}
	
		var f = quickSort(arr);
		console.log(f);
	
	</script>
	
	
	<script>

		/**
		 * 快速排序法
		 */
		
		var tamArr = [3,5,8,45,24,66,88,87,66];

		var s = tamArr.sort(function(a,b) {
			return b-a;
		})
		console.log(s)

		function quckSort(arr) {

			if(arr.length <= 0){
				return arr;
			}

			var absIndex = Math.floor(arr.length / 2),
				abs = arr.splice(absIndex,1),
				left = [],
				rigth = [],
				len = arr.length;

			for(var i = 0; i < len; i++) {
				if(arr[i] < abs){
					left.push(arr[i])
				}else {
					rigth.push(arr[i])
				}
			}

			return quckSort(left).concat(abs, quckSort(rigth));
		}

		var h = quckSort(tamArr);
		console.log(h);

	</script>

	
</body>
</html>